package com.docjohnson.pamphlet.utils;

import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class PamphletPreferences implements Constants {

	private static final int DEFAULT_SCREENSAVER_DELAY = 30000;
	private static final int DEFAULT_ROTATION_SPEED = 550;
	
	private SharedPreferences mSharedPrefs;
	private SharedPreferences.Editor mPrefsEditor;

	public PamphletPreferences(Context context) {
		this.mSharedPrefs = context.getSharedPreferences(DOC_JOHNSON_PREFS,
				Activity.MODE_PRIVATE);
		this.mPrefsEditor = mSharedPrefs.edit();
	}

	public long getScreenSaverDelay() {
		return mSharedPrefs.getLong("screenSaverDelay", DEFAULT_SCREENSAVER_DELAY);
	}
	
	public int getRotationSpeed() {
		return mSharedPrefs.getInt("rotationspeed", DEFAULT_ROTATION_SPEED);
	}

	public void saveScreenSaverDelay(long screenSaverDelay) {
		mPrefsEditor.putLong("screenSaverDelay", screenSaverDelay);
		mPrefsEditor.commit();
	}
	
	public void saveRotationSpeed(int rotationSpeed) {
		mPrefsEditor.putInt("rotationspeed", rotationSpeed);
		mPrefsEditor.commit();
	}

	public Set<String> getScreenSaverImageList() {
		return mSharedPrefs.getStringSet("screenSaverImage", null);
	}

	public void saveScreenSaverImages(Set<String> imageList) {
		mPrefsEditor.putStringSet("screenSaverImage", imageList);
		mPrefsEditor.commit();
	}

	public String getDashboardImage() {
		return mSharedPrefs.getString("dashboardImage", "");
	}

	public void saveDashboardImage(final String dashboardImage) {
		mPrefsEditor.putString("dashboardImage", dashboardImage);
		mPrefsEditor.commit();
	}

	public String getPamphlets() {
		return mSharedPrefs.getString("pamphlets", "");
	}

	public void savePamphlets(final String pamphlets) {
		mPrefsEditor.putString("pamphlets", pamphlets);
		mPrefsEditor.commit();
	}

	public String getUpdateUrl() {
		return mSharedPrefs.getString("updateUrl", "");
	}

	public void saveUpdateUrl(final String updateUrl) {
		mPrefsEditor.putString("updateUrl", updateUrl);
		mPrefsEditor.commit();
	}
	
	public int getAppVersion() {
		return mSharedPrefs.getInt("version", -1);
	}
	
	public void setAppVersion(int version) {
		mPrefsEditor.putInt("version", version);
		mPrefsEditor.commit();
	}
}